package com.fernandomartines.dbcheck.util;

import javax.swing.JOptionPane;

public class DialogUtil {

    private DialogUtil() {
    }

    public static void showDialog(String title, String message, int dialogType) {
        message = "<html><b><font color=\"__color__\">" + title + (message != null ? "</font></b><br><br>" + message : "");
        message = message.replaceAll("\n", "<br>");
        switch (dialogType) {
            case JOptionPane.INFORMATION_MESSAGE:
                title = "Informação";
                message = message.replaceAll("__color__", "#0050aa"); break;
            case JOptionPane.WARNING_MESSAGE:
                title = "Alerta";
                message = message.replaceAll("__color__", "#880000"); break;
            case JOptionPane.ERROR_MESSAGE:
                title = "Erro";
                message = message.replaceAll("__color__", "#990000"); break;
        }
        JOptionPane.showMessageDialog(null, message, title, dialogType);
    }

    public static void showInfoDialog(String title, String message) {
        showDialog(title, message, JOptionPane.INFORMATION_MESSAGE);
    }

    public static void showWarningDialog(String title, String message) {
        showDialog(title, message, JOptionPane.WARNING_MESSAGE);
    }

    public static void showErrorDialog(String title, String message) {
        showDialog(title, message, JOptionPane.ERROR_MESSAGE);
    }

    public static void showInfoDialog(String message) {
        showDialog(message, null, JOptionPane.INFORMATION_MESSAGE);
    }

    public static void showWarningDialog(String message) {
        showDialog(message, null, JOptionPane.WARNING_MESSAGE);
    }

    public static void showErrorDialog(String message) {
        showDialog(message, null, JOptionPane.ERROR_MESSAGE);
    }

    // confirm dialog

    public static int showConfirmDialog(String title, String message, int dialogType) {
        message = "<html><b><font color=\"__color__\">" + title + (message != null ? "</font></b><br><br>" + message: "") + "<br><br>";
        message = message.replaceAll("\n", "<br>");
        switch (dialogType) {
            case JOptionPane.INFORMATION_MESSAGE:
                title = "Informação";
                message = message.replaceAll("__color__", "#0050aa"); break;
            case JOptionPane.WARNING_MESSAGE:
                title = "Alerta";
                message = message.replaceAll("__color__", "#880000"); break;
            case JOptionPane.ERROR_MESSAGE:
                title = "Erro";
                message = message.replaceAll("__color__", "#990000"); break;
        }
        return JOptionPane.showConfirmDialog(null, message, title, dialogType);
    }

    public static int showInfoConfirmDialog(String title, String message) {
        return showConfirmDialog(title, message, JOptionPane.INFORMATION_MESSAGE);
    }

    public static int showWarningConfirmDialog(String title, String message) {
        return showConfirmDialog(title, message, JOptionPane.WARNING_MESSAGE);
    }

    public static int showErrorConfirmDialog(String title, String message) {
        return showConfirmDialog(title, message, JOptionPane.ERROR_MESSAGE);
    }

    public static int showInfoConfirmDialog(String message) {
        return showConfirmDialog(message, null, JOptionPane.INFORMATION_MESSAGE);
    }

    public static int showWarningConfirmDialog(String message) {
        return showConfirmDialog(message, null, JOptionPane.WARNING_MESSAGE);
    }

    public static int showErrorConfirmDialog(String message) {
        return showConfirmDialog(message, null, JOptionPane.ERROR_MESSAGE);
    }

}
